package com.boat.framework.base.logging.logback;

import java.net.InetAddress;
import java.net.UnknownHostException;

import com.boat.framework.base.setting.EnvProps;

import ch.qos.logback.core.PropertyDefinerBase;
import lombok.extern.slf4j.Slf4j;

/**
 * 获取本机内部IP，进行多节点日志隔离。解决“多容器部署+同个共享盘输出日志”，导致的日志输出到上一天问题
 * 
 * @author 周江
 *
 */
@Slf4j
public class IpPropertyProvider extends PropertyDefinerBase {

	@Override
	public String getPropertyValue() {
		String localIp = null;
		try {
			localIp = InetAddress.getLocalHost().getHostAddress();
		} catch (UnknownHostException ex) {
			log.warn("获取IP失败，错误消息：" + ex.getMessage(), ex);
		}
		
		//部署方式设置为容器部署
		EnvProps.instance().setK8s(true);
		
		return localIp;
	}

}
